Skip to content

fix: preserve half-width slot placement on save/load (#1248)#1302

Merged
ggfevans merged 2 commits intomainfrom
fix/1248-save-load-half-width-slot-position
Feb 25, 2026
Merged

fix: preserve half-width slot placement on save/load (#1248)#1302
ggfevans merged 2 commits intomainfrom
fix/1248-save-load-half-width-slot-position

Conversation

@ggfevans
Copy link
Collaborator

@ggfevans ggfevans commented Feb 20, 2026

User description

Summary

  • preserve device_types[].slot_width during YAML serialization
  • preserve racks[].devices[].slot_position during YAML serialization
  • add a YAML round-trip regression test covering half-width left-slot placement

Test Plan

  • npm run test:run -- src/tests/yaml-roundtrip.test.ts
  • npm run build
  • codeant static-analysis --uncommitted --fail-on INFO
  • codeant security-analysis --uncommitted --fail-on INFO
  • codeant secrets --uncommitted --fail-on all
  • coderabbit --prompt-only --type uncommitted
  • npm run lint (fails on unrelated baseline issues in api/src/* and scripts/*)
  • npm run test:run (fails on unrelated baseline timeouts in src/tests/App.startScreen.test.ts and src/tests/App.cleanupPrompt.test.ts)

Closes #1248


CodeAnt-AI Description

Preserve half-width device slot width and placement in layout YAML

What Changed

  • Saved layout YAML now includes device type slot_width so half-width devices retain their width after save and reload
  • Saved layout YAML now includes placed device slot_position so left/right placement of half-width devices is retained after import
  • Added a regression test that serializes and deserializes a layout with a half-width device placed left and verifies both slot_width and slot_position are preserved

Impact

✅ Preserved half-width device placement after save/load
✅ Accurate rack layout after YAML import
✅ Fewer layout round-trip regressions

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 20, 2026

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

📝 Walkthrough

Walkthrough

Adds YAML serialization ordering for slot_width on DeviceType and slot_position on PlacedDevice; includes a new YAML round-trip test that verifies a half-width device's slot_width and slot_position are preserved across serialize/parse.

Changes

Cohort / File(s) Summary
YAML serialization
src/lib/utils/yaml.ts
Include slot_width in DeviceType field ordering (after u_height) and include slot_position in PlacedDevice field ordering (after position). Updated inline comments to reflect new fields.
Round-trip test
src/tests/yaml-roundtrip.test.ts
New test that builds a layout with a half-width device (slot_width: 1) placed with slot_position: "left", serializes to YAML, parses back, and asserts both fields are preserved.

Sequence Diagram(s)

(Skipped — changes are limited to serialization ordering and a unit test; no multi-component sequential flow to visualize.)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • #835: Adds UI/creation logic that sets slot_width and records slot_position — relates to serialization of those fields.
  • #829: Threads slot_position through placement/store APIs; complements YAML persistence added here.
  • #848: Updates rendering logic to respect slot_width; benefits from this PR preserving that field in persistence.

Poem

🐰 I hopped through lines of YAML bright,

Saved a left-slot friend at night.
Half-width kept, not lost in fog,
Slot and side are snug as a log,
Hop, save, load — hooray, all right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: preserving half-width slot placement during save/load cycles, which aligns with the primary objectives.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #1248: preserves slot_width and slot_position in YAML serialization, and adds a round-trip regression test.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #1248: YAML field ordering updates and round-trip testing, with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description clearly relates to the changeset, describing the preservation of slot_width and slot_position in YAML serialization with a corresponding test.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/1248-save-load-half-width-slot-position

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeant-ai codeant-ai bot added the size:M This PR changes 30-99 lines, ignoring generated files label Feb 20, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 20, 2026

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Test coverage edge cases
    The new test validates left placement for half-width devices. Consider adding a complementary case for right placement and the absence of device_types (or a full-width device) to ensure behavior is correct in those scenarios and that serialization doesn't regress when device types are missing or reordered.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 20, 2026

CodeAnt AI finished reviewing your PR.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/tests/yaml-roundtrip.test.ts`:
- Line 27: Remove the redundant override `face: "front"` in the test fixture
since `createTestDevice` already defaults to face="front"; locate the test
object in yaml-roundtrip.test.ts where `face: "front"` is set (the literal shown
in the diff) and delete that property so the test relies on the factory default
from `createTestDevice`.

id: "placed-1",
device_type: halfWidth.slug,
position: 10,
face: "front",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Redundant face override

face: "front" is already the default in createTestDevice, so this override is a no-op.

🧹 Suggested cleanup
  createTestDevice({
    id: "placed-1",
    device_type: halfWidth.slug,
    position: 10,
-   face: "front",
    slot_position: "left",
  }),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
face: "front",
createTestDevice({
id: "placed-1",
device_type: halfWidth.slug,
position: 10,
slot_position: "left",
}),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tests/yaml-roundtrip.test.ts` at line 27, Remove the redundant override
`face: "front"` in the test fixture since `createTestDevice` already defaults to
face="front"; locate the test object in yaml-roundtrip.test.ts where `face:
"front"` is set (the literal shown in the diff) and delete that property so the
test relies on the factory default from `createTestDevice`.

ggfevans and others added 2 commits February 25, 2026 01:01
The createTestDevice factory already defaults face to "front", so the
explicit assignment was unnecessary. Addresses CodeRabbit review feedback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ggfevans ggfevans force-pushed the fix/1248-save-load-half-width-slot-position branch from 5b1ae17 to 41ede6f Compare February 25, 2026 09:02
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 25, 2026

CodeAnt AI is running Incremental review


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@ggfevans ggfevans enabled auto-merge (squash) February 25, 2026 09:02
@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Feb 25, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 25, 2026

Sequence Diagram

The PR ensures device_types.slot_width and placed device slot_position are included in YAML output so a serialize -> parse round-trip preserves half-width device placement; the test covers serializing a layout and parsing it back to assert both fields survive.

sequenceDiagram
    participant Test
    participant YAMLUtil
    participant Serializer
    participant Parser

    Test->>YAMLUtil: serializeLayoutToYaml(layout with half-width device & left slot)
    YAMLUtil->>Serializer: include device_types.slot_width and devices.slot_position
    Serializer-->>YAMLUtil: YAML string (layout)
    YAMLUtil->>Parser: parseLayoutYaml(YAML string)
    Parser-->>YAMLUtil: restored layout (slot_width and slot_position preserved)
    YAMLUtil-->>Test: return restored layout
    Test->>Test: assert restored.device_types.slot_width == 1 and restored.racks[0].devices[0].slot_position == "left"
Loading

Generated by CodeAnt AI

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 25, 2026

CodeAnt AI Incremental review completed.

@ggfevans ggfevans merged commit 3661eba into main Feb 25, 2026
7 checks passed
@ggfevans ggfevans deleted the fix/1248-save-load-half-width-slot-position branch February 25, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Save/load restores half-width devices as full-width

1 participant